import pymysql

def main():
    id = int(input('请输入需要编辑的角色的编号：'))
    name = input('请输入角色新名字：')
    age = int(input('请输入角色等级：'))

    conn = pymysql.connect(host='47.110.246.28',port=3306,
                           user='jiadashuai',password='977911',
                           database='test1_db',charset='utf8')
    try:
        with conn.cursor() as cursor:
            sql = 'update STUDENT set name=%s , age=%s where id=%s'
            result = cursor.execute(sql,(name,age,id))
            if result == 1:
                print('角色更新成功')
            conn.commit()
    except pymysql.MySQLError as error:
        print(error)
        conn.rollback()
    finally:
        conn.close()

if __name__ == '__main__':
    main()
